package com.thyme.web.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * @author ah.caixiaodong@aisino.com
 * @ClassName TimeFilter
 * @Description TODO
 * @Date 2019/6/5 10:30
 */
//@Component
public class TimeFilter implements Filter {

    private static final Logger logger = LoggerFactory.getLogger(TimeFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("time filter init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        logger.info("time filter start");
        long start = System.currentTimeMillis();
        filterChain.doFilter(request,response);
        logger.info("time filter 耗时"+ (System.currentTimeMillis() - start));
        logger.info("time filter finish");
    }

    @Override
    public void destroy() {
        logger.info("time filter destroy");
    }
}
